import Storage from 'web-storage-cache' //本地存储库

const localStorage = new Storage()
// 设置
export function setLocalStorage(key, value) {
    return localStorage.set(key, value)
}
// 获取
export function getLocalStorage(key) {
    return localStorage.get(key)
}
// 删除某个key值
export function removeLocalStorage(key) {
    return localStorage.delete(key)
}
// 清空
export function clearLocalStorage() {
    return localStorage.clear()
}

// 为每本书设置一个对象 因为每本书的设置是不同的
export function setBookObject(fileName, key, value) {
    let book = getLocalStorage(`${fileName}-info`)
    if (!book) {
        book = {}
    }
    book[key] = value
    setLocalStorage(`${fileName}-info`, book)
}
//获取
export function getBookObject(fileName, key) {
    let book = getLocalStorage(`${fileName}-info`)
    if (!book) {
        return null
    }
    return book[key]
}
// 设置字体
export function saveFontFamily(fileName, font) {
    return setBookObject(fileName, 'fontFamily', font)
}
// 获取字体
export function getFontFamily(fileName) {
    return getBookObject(fileName, 'fontFamily')
}
// 设置字号
export function getFontSize(fileName) {
    return getBookObject(fileName, 'fontSize')
}
// 获取字号
export function saveFontSize(fileName, fontSize) {
    setBookObject(fileName, 'fontSize', fontSize)
}
// 获取默认语言
export function getLocale() {
    return getLocalStorage('locale')
}
// 设置默认语言
export function saveLocale(locale) {
    return setLocalStorage('locale', locale)
}
// 获取主题
export function getTheme(fileName) {
    return getBookObject(fileName, 'theme')
}
// 设置主题
export function saveTheme(fileName, theme) {
    setBookObject(fileName, 'theme', theme)
}
// 获取阅读进度
export function getLocation(fileName) {
    return getBookObject(fileName, 'location')
}
// 设置阅读进度
export function saveLocation(fileName, location) {
    setBookObject(fileName, 'location', location)
}
// 获取阅读时间
export function getReadTime(fileName) {
    return getBookObject(fileName, 'time')
}
// 设置阅读时间
export function saveReadTime(fileName, theme) {
    setBookObject(fileName, 'time', theme)
}
// 获取封面图片
export function getCover(fileName) {
    return getBookObject(fileName, 'cover')
}
// 设置封面图片
export function saveCover(fileName, cover) {
    setBookObject(fileName, 'cover', cover)
}
